package com.emeraldparser.symbol;

import com.emeraldparser.symbol.SymbolClass.State;
import com.emeraldparser.util.HashCodes;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;

public class NestedSymbolClassState implements SymbolClass.State {

	private final SymbolClass parentSymbolClass;
	private final SymbolClass.State childSymbolClassState;
	private final transient int hashCode;

	public NestedSymbolClassState(SymbolClass parentSymbolClass, State childSymbolClassState) {
		this.parentSymbolClass = Preconditions.checkNotNull(parentSymbolClass, "Parent symbol class must not be null");
		this.childSymbolClassState = Preconditions.checkNotNull(childSymbolClassState, "Child symbol class state must not be null");
		this.hashCode = HashCodes.classSpecificHashCode(NestedSymbolClass.class, parentSymbolClass, childSymbolClassState);
	}

	public SymbolClass getParentSymbolClass() {
		return parentSymbolClass;
	}

	public SymbolClass.State getChildSymbolClassState() {
		return childSymbolClassState;
	}

	@Override
	public int hashCode() {
		return hashCode;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null) {
			return false;
		}
		
		if (getClass() != obj.getClass()) {
			return false;
		}
		
		NestedSymbolClassState other = (NestedSymbolClassState) obj;
		
		return Objects.equal(parentSymbolClass, other.parentSymbolClass)
		    && Objects.equal(childSymbolClassState, other.childSymbolClassState);
	}

}
